﻿using System;
using System.Collections.Generic;
using System.Text;
using DBUtility;
using ATSIDAL;
using ATSModel;
using System.Data.SqlClient;
using System.Data;

namespace ATSDAL
{
    public class TCalElectricalProperty : BaseRepository_DT<TCalElectricalPropertyItem>,ITCalElectricalPropertyItem
    {
        private const String PRAM_Cali_RecordTime = "@RecordTime";
        private const String PRAM_Cali_InstrumentID = "@InstrumentID";

        private const String PRAM_Cali_Tdate1 = "@Time1";
        private const String PRAM_Cali_TBand1 = "@Band1";
        private const String PRAM_Cali_StandingWaveOne1 = "@StandingWaveOne1";
        private const String PRAM_Cali_StandingWaveTwo1 = "@StandingWaveTwo1";
        private const String PRAM_Cali_Quarantine1 = "@Quarantine1";

        private const String PRAM_Cali_Tdate2 = "@Time2";
        private const String PRAM_Cali_TBand2 = "@Band2";
        private const String PRAM_Cali_StandingWaveOne2 = "@StandingWaveOne2";
        private const String PRAM_Cali_StandingWaveTwo2 = "@StandingWaveTwo2";
        private const String PRAM_Cali_Quarantine2 = "@Quarantine2";

        private const String PRAM_Cali_Tdate3 = "@Time3";
        private const String PRAM_Cali_TBand3 = "@Band3";
        private const String PRAM_Cali_StandingWaveOne3 = "@StandingWaveOne3";
        private const String PRAM_Cali_StandingWaveTwo3 = "@StandingWaveTwo3";
        private const String PRAM_Cali_Quarantine3 = "@Quarantine3";
        
        private const String PRAM_Cali_UserID = "@UserID";
        private const String PRAM_Cali_UserID2 = "@UserID2";
        private const String PRAM_Cali_InstrumentID1 = "@InstrumentID1";
        public IList<TCalElectricalPropertyItem> LoadEntities()
        {
            return null;
        }

        public TCalElectricalPropertyItem LoadEntity<T1>(T1 Id)
        {
            return null;
        }


        public IList<TCalElectricalPropertyItem> GetElectricalPropertyItemByDT(DateTime starttime, DateTime stoptime) 
        {
            SqlParameter[] testParms = GetDTParameters();

            testParms[0].Value = starttime;
            testParms[1].Value = stoptime;

            return ExcuteSqlToGetEntities("CallElectricalRecordBYDT", testParms);
        }

        public IList<TCalElectricalPropertyItem> GetElectricalPropertyItemBySN(String InstrumentID)
        {
            SqlParameter parm = new SqlParameter(PRAM_Cali_InstrumentID, SqlDbType.NVarChar, 50);
            parm.Value = InstrumentID;
            return ExcuteSqlToGetEntities("CalRecord_select_SN", parm);
        }
        public IList<TCalElectricalPropertyItem> GetElectricalPropertyItem()
        {


           return ExcuteSqlToGetEntities("CallElectricalRecord");

           //  return ExcuteSqlToGetEntities(" CallElectricalRecord1111111111");

        }

        public IList<TCalElectricalPropertyItem> GetElectricalPropertyItemByDTAndID(DateTime starttime, DateTime stoptime, string InstrumentID)
        {
            SqlParameter[] ptestParms = GetUserDTParameters();
            ptestParms[0].Value = starttime;
            ptestParms[1].Value = stoptime;
            ptestParms[2].Value = InstrumentID;
            return ExcuteSqlToGetEntities("CallElecRecordBYDTAndSN", ptestParms);
        }

        public override TCalElectricalPropertyItem GetEntityRecord(SqlDataReader rdr)
        {
            TCalElectricalPropertyItem pro = new TCalElectricalPropertyItem
            {
                RecordTime = rdr.GetValue(0).ToString(),
                InstrumentID = rdr.GetValue(1).ToString(),
                Time1 = rdr.GetValue(2).ToString(),
                Band1 = rdr.GetValue(3).ToString(),
                StandingWaveOne1 = rdr.GetValue(4).ToString(),
                StandingWaveTwo1 = rdr.GetValue(5).ToString(),
                Quarantine1 = rdr.GetValue(6).ToString(),
                Time2 = rdr.GetValue(7).ToString(),
                Band2 = rdr.GetValue(8).ToString(),
                StandingWaveOne2 = rdr.GetValue(9).ToString(),
                StandingWaveTwo2 = rdr.GetValue(10).ToString(),
                Quarantine2 = rdr.GetValue(11).ToString(),
                Time3 = rdr.GetValue(12).ToString(),
                Band3 = rdr.GetValue(13).ToString(),
                StandingWaveOne3 = rdr.GetValue(14).ToString(),
                StandingWaveTwo3 = rdr.GetValue(15).ToString(),
                Quarantine3 = rdr.GetValue(16).ToString(),
                UserID = rdr.GetValue(17).ToString(),
                UserID2 = rdr.GetValue(18).ToString()
                
            };
            return pro;
        }

        public override TCalElectricalPropertyItem GetEntityRecord()
        {
            TCalElectricalPropertyItem pro = new TCalElectricalPropertyItem();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "TTest_Insert1";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return null;
        }



        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PRAM_Cali_RecordTime, SqlDbType.NVarChar, 200),
					new SqlParameter(PRAM_Cali_InstrumentID, SqlDbType.NVarChar, 200),
                    new SqlParameter(PRAM_Cali_Tdate1,  SqlDbType.NVarChar, 200),
                    new SqlParameter(PRAM_Cali_TBand1, SqlDbType.NVarChar, 200),
                    new SqlParameter(PRAM_Cali_StandingWaveOne1, SqlDbType.NVarChar, 50),
					new SqlParameter(PRAM_Cali_StandingWaveTwo1, SqlDbType.NVarChar, 50),
                    new SqlParameter(PRAM_Cali_Quarantine1, SqlDbType.NVarChar, 50),
                     new SqlParameter(PRAM_Cali_Tdate2,  SqlDbType.NVarChar, 200),
                    new SqlParameter(PRAM_Cali_TBand2, SqlDbType.NVarChar, 200),
                    new SqlParameter(PRAM_Cali_StandingWaveOne2, SqlDbType.NVarChar, 50),
					new SqlParameter(PRAM_Cali_StandingWaveTwo2, SqlDbType.NVarChar, 50),
                    new SqlParameter(PRAM_Cali_Quarantine2, SqlDbType.NVarChar, 50),
                     new SqlParameter(PRAM_Cali_Tdate3,  SqlDbType.NVarChar, 200),
                    new SqlParameter(PRAM_Cali_TBand3, SqlDbType.NVarChar, 200),
                    new SqlParameter(PRAM_Cali_StandingWaveOne3, SqlDbType.NVarChar, 50),
					new SqlParameter(PRAM_Cali_StandingWaveTwo3, SqlDbType.NVarChar, 50),
                    new SqlParameter(PRAM_Cali_Quarantine3, SqlDbType.NVarChar, 50),
                    new SqlParameter(PRAM_Cali_UserID, SqlDbType.NVarChar, 50),
					new SqlParameter(PRAM_Cali_UserID2, SqlDbType.NVarChar, 50)
                   
                    
                };
            return parms;
        }

        public override void SetParameters(TCalElectricalPropertyItem tpti, params SqlParameter[] Parms)
        {
            Parms[0].Value = tpti.RecordTime;
            Parms[1].Value = tpti.InstrumentID;
            Parms[2].Value = tpti.Time1;
            Parms[3].Value = tpti.Band1;
            Parms[4].Value = tpti.StandingWaveOne1;
            Parms[5].Value = tpti.StandingWaveTwo1;
            Parms[6].Value = tpti.Quarantine1;
            Parms[7].Value = tpti.Time2;
            Parms[8].Value = tpti.Band2;
            Parms[9].Value = tpti.StandingWaveOne2;
            Parms[10].Value = tpti.StandingWaveTwo2;
            Parms[11].Value = tpti.Quarantine2;
            Parms[12].Value = tpti.Time3;
            Parms[13].Value = tpti.Band3;
            Parms[14].Value = tpti.StandingWaveOne3;
            Parms[15].Value = tpti.StandingWaveTwo3;
            Parms[16].Value = tpti.Quarantine3;
            Parms[17].Value = tpti.UserID;
            Parms[18].Value = tpti.UserID2;
          

        }
        private SqlParameter[] GetUserDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
            {
                new SqlParameter(PARM_STARTTIME, SqlDbType.DateTime,8),
                new SqlParameter(PARM_STOPTIME, SqlDbType.DateTime,8),
                new SqlParameter(PRAM_Cali_InstrumentID1, SqlDbType.NVarChar, 50),
             
            };
            return parms;
        }

    }
}
